#!/usr/bin/env Rscript
library(tidyverse)
library(CrispRVariants)
library(argparse)

# to use in shell
parser <- ArgumentParser()

parser$add_argument("-i", "--input", nargs = '+', help="Input ab1 file(s) *")

input_args <- parser$parse_args()

input_ab1 <- input_args$input

read_header <- basename(input_ab1) |>
  str_remove('.ab1')

walk2(read_header, input_ab1, \(x, y)abifToFastq(x, y, str_glue(x, '.fastq'), trim = FALSE))

# use in rstudio
ab1dir <- '/home/bill/文档/Lab/4_Missions/Ji-Liu 202x FPP novel DAMP/fasta/ab1'

setwd(ab1dir)

ab1list <- list.files('.', pattern = 'ab1', full.names = T)

readnames <- str_extract(ab1list, 'V.+_5')

walk2(readnames, ab1list, \(x, y)abifToFastq(x, y, str_glue(x, '.fastq')))
